package com.example.yls.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.content.DialogInterface;
import android.app.AlertDialog;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn_1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                showSimpleAppDialog();
            }


        });
        findViewById(R.id.btn_2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showSimpleDialog();

            }

        });
        findViewById(R.id.btn_3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showSimplev7Dialog();

            }
        });
    }

    private void showSimplev7Dialog() {
        final String[] cities = {"北京", "上海", "广州", "深圳"};
        final String[] xingbie = {"男", "女", "未知"};
        new AlertDialog.Builder(MainActivity.this)
                .setTitle("选择性别")
//                .setItems(cities, new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//                        Toast.makeText(MainActivity.this, "您选择了" + cities[i],
//                                Toast.LENGTH_SHORT).show();
//                    }
//                })
                .setSingleChoiceItems(xingbie, 0, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Toast.makeText(MainActivity.this, "您的性别是" + xingbie[i],
                        Toast.LENGTH_SHORT).show();
            }
        })


          .setIcon(R.mipmap.ic_launcher)
                .create()
                .show();
    }


    private void showSimpleAppDialog() {
        new AlertDialog.Builder(MainActivity.this)
                .setTitle("弹出警告框")
                .setIcon(R.mipmap.ic_launcher)
                .setMessage("确定删除消息？")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface,
                                        int i) {

                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                })
                .setNeutralButton("忽略", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                })
                .create()
                .show();
    }


    private void showSimpleDialog() {
        new AlertDialog.Builder(MainActivity.this)
                .setTitle("这是标题")
                .setIcon(R.mipmap.ic_launcher)
                .setMessage("这是消息")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                })
                .create()
                .show();
    }
}